package yang.cn.com.greendaoapp;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import yang.cn.com.greendaoapp.adapter.TabPagerAdapter;
import yang.cn.com.greendaoapp.base.BaseActivity;
import yang.cn.com.greendaoapp.bean.EventCenter;
import yang.cn.com.greendaoapp.fragment.AllMainFragment;
import yang.cn.com.greendaoapp.fragment.LocalMainFragment;
import yang.cn.com.greendaoapp.view.CustomViewPager;

public class MainActivity extends BaseActivity {


    @Bind(R.id.top_rg_a)
    RadioButton top_rg_a;
    @Bind(R.id.top_rg_b)
    RadioButton top_rg_b;
    @Bind(R.id.main_top_rg)
    RadioGroup main_top_rg;
    @Bind(R.id.main_viewpager)
    CustomViewPager  main_viewpager;

    @Override
    public void onEventComming(EventCenter var1) {

    }

    @Override
    public boolean isBindEventBusHere() {
        return false;
    }
    private List<String> mTitleList = new ArrayList<>();
    private List<Fragment> fragments = new ArrayList<>();
    @Override
    public void initViewAndEvent() {
        fragments.add(new AllMainFragment());
        fragments.add(new LocalMainFragment());
        TabPagerAdapter pagerAdapter = new TabPagerAdapter(getSupportFragmentManager(), mTitleList, fragments);
        main_viewpager.setAdapter(pagerAdapter);
        main_top_rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (checkedId == top_rg_a.getId()) main_viewpager.setCurrentItem(0);
                else if (checkedId == top_rg_b.getId()) main_viewpager.setCurrentItem(1);
            }
        });

        //设置默认选中页
        main_viewpager.setCurrentItem(0);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_main_fragment;
    }
    @Override
    public void onBackPressed() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
        builder.setTitle("提示");
        builder.setMessage("留下再体验一下？");
        builder.setPositiveButton("好的", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });

        builder.setNegativeButton("不要了", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                finish();
            }
        });

        builder.create().show();
    }
}
